package vectors;

public class Direction implements Location{
	
	private final int nod;
	
	private double[] phis;
	private double theta;

	public Direction(double theta){
		this(new double[0], theta);
	}
	
	public Direction(double[] phis, double theta){
		this.phis = phis;
		this.theta = theta;
		this.nod = phis.length+2;
	}
	
	// This assumes that theta=0 points at X, theta = pi/2 points at Y, and when each phi is 0, it points at an axis.
	public Vector generateUnitVector(){
		double[] vals = new double[nod+1];
		double curSineTotal = 1;
		for(int i=0;i<phis.length;i++){
			vals[i] = curSineTotal*Math.cos(phis[i]);
			curSineTotal*=Math.sin(phis[i]);
		}
		vals[phis.length] = curSineTotal*Math.cos(theta);
		vals[phis.length+1] = curSineTotal*Math.sin(theta);
		return new Vector(vals);
	}
	
	public double acos(Direction dir) {
		return Math.acos(this.generateUnitVector().dot(dir.generateUnitVector()));
	}
	
	public int getNOD(){
		return nod;
	}
	
	public void setTheta(double theta){
		this.theta = theta;
	}
	
	public double getPhi(int index){
		return phis[index];
	}
	
	public void setPhi(int index, double value){
		phis[index] = value;
	}

	public double getTheta() {
		return theta;
	}
}
